﻿Imports System.Data
Imports Mysoft.Map.Data

Partial Public Class SaleModiApply_Tf_Edit
    Inherits Mysoft.Map.Application.Security.AppPage

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Dim MyBizParamMNG As New Mysoft.PubProject.Business.BizParamMNG

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码

        Dim strMode, strSaleGUID As String
        strMode = Request.QueryString("mode")
        strSaleGUID = Request.QueryString("SaleGUID")

        '当天时间
        Dim strToday As String
        strToday = Format(Today(), "yyyy-MM-dd")
        txtToday.Value = strToday

        '当前操作员
        Dim strUserName As String
        strUserName = Session("UserName")
        txtUserName.Value = strUserName

        '新增模式

        '取出当前销售单取出对应的客户名称、客户GUID、房间、房间GUID、项目GUID、单位GUID、销售单类型,交易GUID
        Dim dtTrade As DataTable
        Dim strSQL As String
        Dim strCstName, strCstAllGUID, strRoominfo, strRoomGUID, strProjGUID, strBUGUID, strSaletype, strTradeGUID As String

        Dim strBldArea, strTnArea, strPrice, strTnPrice, strTotal, strCalMode, strPayformName, strDiscntValue, strDiscntRemark, strBldCjPrice, strTnCjPrice, strRoomTotal As String
        Dim strZxBz, strZxPrice, strZxTotal, strIsZxkbrht, strFsTotal, strRmbCjTotal, strBz, strExRate, strCjTotal As String

        strSQL = "SELECT top 1 CstName,CstAllGUID,Roominfo,RoomGUID,ProjGUID,BUGUID,(case when Saletype='合同' then '合同' else '定单' end)  as SaleType,TradeGUID " & _
              ",[BldArea],[TnArea],[Price],[TnPrice],[Total],[CalMode],[PayformName],[DiscntValue],[DiscntRemark] ,[BldCjPrice],[TnCjPrice],[RoomTotal]  " & _
                    "	,[ZxBz],[ZxPrice] ,[ZxTotal],[IsZxkbrht],[FsTotal],[RmbCjTotal],[Bz],[ExRate],[CjTotal]  " & _
                 "FROM vs_trade  " & _
                 "WHERE SaleGUID='" & strSaleGUID & "'"
        dtTrade = MyDB.GetDataTable(strSQL)

        If dtTrade.Rows.Count() > 0 Then
            strTradeGUID = dtTrade.Rows(0).Item("tradeguid").ToString()
            strCstName = dtTrade.Rows(0).Item("CstName").ToString()
            strCstAllGUID = dtTrade.Rows(0).Item("CstAllGUID").ToString()
            strRoominfo = dtTrade.Rows(0).Item("Roominfo").ToString()
            strRoomGUID = dtTrade.Rows(0).Item("RoomGUID").ToString()
            strProjGUID = dtTrade.Rows(0).Item("ProjGUID").ToString()
            strBUGUID = dtTrade.Rows(0).Item("BUGUID").ToString()
            strSaletype = dtTrade.Rows(0).Item("Saletype").ToString()
            strBldArea = dtTrade.Rows(0).Item("BldArea").ToString()
            strTnArea = dtTrade.Rows(0).Item("TnArea").ToString()
            strPrice = dtTrade.Rows(0).Item("price").ToString()
            strTnPrice = dtTrade.Rows(0).Item("TnPrice").ToString()
            strTotal = dtTrade.Rows(0).Item("total").ToString()
            strCalMode = dtTrade.Rows(0).Item("calmode").ToString()
            strPayformName = dtTrade.Rows(0).Item("PayformName").ToString()

            strDiscntValue = dtTrade.Rows(0).Item("DiscntValue").ToString()
            strDiscntRemark = dtTrade.Rows(0).Item("DiscntRemark").ToString()
            strBldCjPrice = dtTrade.Rows(0).Item("BldCjPrice").ToString()
            strTnCjPrice = dtTrade.Rows(0).Item("TnCjPrice").ToString()
            strRoomTotal = dtTrade.Rows(0).Item("RoomTotal").ToString()
            strZxBz = dtTrade.Rows(0).Item("ZxBz").ToString()
            strZxPrice = dtTrade.Rows(0).Item("ZxPrice").ToString()

            strZxPrice = dtTrade.Rows(0).Item("ZxTotal").ToString()
            strIsZxkbrht = dtTrade.Rows(0).Item("IsZxkbrht").ToString()
            strFsTotal = dtTrade.Rows(0).Item("FsTotal").ToString()
            strRmbCjTotal = dtTrade.Rows(0).Item("RmbCjTotal").ToString()
            strBz = dtTrade.Rows(0).Item("Bz").ToString()
            strExRate = dtTrade.Rows(0).Item("ExRate").ToString()
            strCjTotal = dtTrade.Rows(0).Item("CjTotal").ToString()
        Else
            strBldArea = "0"
            strTnArea = "0"
            strPrice = "0"
            strTnPrice = "0"
            strTotal = "0"
            strCalMode = ""
            strPayformName = ""

            strDiscntValue = "0"
            strDiscntRemark = ""
            strBldCjPrice = "0"
            strTnCjPrice = "0"
            strRoomTotal = "0"
            strZxBz = ""
            strZxPrice = "0"

            strZxPrice = "0"
            strIsZxkbrht = "0"
            strFsTotal = "0"
            strRmbCjTotal = "0"
            strBz = ""
            strExRate = "0"
            strCjTotal = "0"
        End If
         

        '取出当前交易对应的已交款金额
        Dim strPay As String
        If strTradeGUID <> "" Then
            strSQL = "SELECT sum(BeforeRmbYe) as Pay FROM s_getin WHERE SaleGUID='" & strTradeGUID & "' and (status<>'作废' or status is null)"
            strPay = MyDB.GetDataItemDecimal(strSQL).ToString()
        Else
            strPay = "0"
        End If

          
        Dim strApplyTypeOption As String = "退房"

            If strMode = "1" Then
                '初始化页面
            appForm.DefaultValueXml = "<xml>" & _
                                        "<BUGUID defaultvalue='" & strBUGUID & "'/>" & _
                                        "<ProjGUID defaultvalue='" & strProjGUID & "'/>" & _
                                        "<SaleGUID defaultvalue='" & strSaleGUID & "'  defaulttext='详情'/>" & _
                                        "<SaleType defaultvalue='" & strSaletype & "'/>" & _
                                        "<RoomGUID defaultvalue='" & strRoomGUID & "'/>" & _
                                        "<CstName defaultvalue='" & strCstName & "'/>" & _
                                        "<CstGUID defaultvalue='" & strCstAllGUID & "'/>" & _
                                             "<appForm_TradeGUID defaultvalue='" & strTradeGUID & "'/>" & _
                                         "<appForm_BldArea defaultvalue='" & strBldArea & "'/>" & _
                                        "<appForm_TnArea defaultvalue='" & strTnArea & "'/>" & _
                                        "<appForm_Price defaultvalue='" & strPrice & "'/>" & _
                                        "<appForm_TnPrice defaultvalue='" & strTnPrice & "'/>" & _
                                        "<appForm_Total defaultvalue='" & strTotal & "'/>" & _
                                        "<appForm_CalMode defaultvalue='" & strCalMode & "'/>" & _
                                        "<appForm_PayformName defaultvalue='" & strPayformName & "'/>" & _
                                        "<appForm_DiscntValue defaultvalue='" & strDiscntValue & "'/>" & _
                                        "<appForm_BldCjPrice defaultvalue='" & strBldCjPrice & "'/>" & _
                                        "<appForm_TnCjPrice defaultvalue='" & strTnCjPrice & "'/>" & _
                                        "<appForm_FsTotal defaultvalue='" & strFsTotal & "'/>" & _
                                        "<appForm_CjTotal defaultvalue='" & strCjTotal & "'/>" & _
                                        "<ApproveState defaultvalue='待审批'/>" & _
                                        "<Pay defaultvalue='" & strPay & "'/>" & _
                                        "<CstGUID1 defaultvalue='" & strCstAllGUID & "' defaulttext='" & strCstName & "'/>" & _
                                        "<RoomGUID1 defaultvalue='" & strRoomGUID & "' defaulttext='" & strRoominfo & "'/>" & _
                                        "<ApplyBy defaultvalue='" & strUserName & "'/>" & _
                                        "<ApplyDate defaultvalue='" & strToday & "'/>" & _
                                        "<ApplyType defaultvalue='" & strApplyTypeOption & "'/>" & _
                                        "</xml>"
            '"<appForm_RmbCjTotal defaultvalue='" & strRmbCjTotal & "'/>" & _
            ' "<appForm_ExRate defaultvalue='" & strExRate & "'/>" & _
            '"<appForm_RoomTotal defaultvalue='" & strRoomTotal & "'/>" & _
            '"<appForm_Bz defaultvalue='" & strBz & "'/>" & _
            ' "<appForm_ZxBz defaultvalue='" & strZxBz & "'/>" & _
            '                            "<appForm_ZxPrice defaultvalue='" & strZxPrice & "'/>" & _
            '                             "<appForm_ZxTotal defaultvalue='" & strZxTotal & "'/>" & _
            '                            "<appForm_IsZxkbrht defaultvalue='" & strIsZxkbrht & "'/>" & _
            ' "<appForm_DiscntRemark defaultvalue='" & strDiscntRemark & "'/>" & _          

            End If

        '退房是否可用，1可用、0不可用
        Dim strEnableTfSh As String = MyBizParamMNG.GetBizParamConfig("s_EnableTfSh", strProjGUID)      '启用退房审批 ( "0"：不启用；"1"：启用)
        strEnableTfSh = IIf(strEnableTfSh = "", "1", strEnableTfSh)
        txtBgShConfig.text = strEnableTfSh
       
    End Sub

    Protected Overrides Sub ConfigureForm()
        appForm.Execute()
    End Sub

End Class
